package com.xiegk.ticket;

import org.springframework.stereotype.Component;

/**
 * 单应用同步锁
 * - synchronized
 *
 * @author xgk
 * @date 2022/2/20
 */
@Component
public class TicketSync01 {
    private int number = 50;

    // 同步锁 - synchronized
    public synchronized void sale() {
        if (number > 0) {
            System.out.println(Thread.currentThread().getName() + "\t" + "卖出第" + (number--) + "\t还剩下：" + number);
        }
    }
}
